//
//  ZWJUploadImageApi.m
//  Free
//
//  Created by 张炜健 on 2018/5/7.
//  Copyright © 2018年 张炜健. All rights reserved.
//

#import "ZWJUploadImageApi.h"
#import <AFNetworking/AFNetworking.h>
@implementation ZWJUploadImageApi{
    UIImage *_image;
}

- (id)initWithImage:(UIImage *)image {
    self = [super init];
    if (self) {
        _image = image;
    }
    return self;
}

- (YTKRequestMethod)requestMethod {
    return YTKRequestMethodPOST;
}

- (NSString *)requestUrl {
    return @"/Outsourcing-Free-Web/ad/file/webupload1.apple";
}
//返回类型 HTTP 和 JSON 两种
- (YTKRequestSerializerType)requestSerializerType {
    return YTKRequestSerializerTypeHTTP;
}
//请求类型 HTTP 和 JSON 两种
-(YTKResponseSerializerType)responseSerializerType{
    return YTKResponseSerializerTypeHTTP;
}
- (AFConstructingBlock)constructingBodyBlock {
    return ^(id<AFMultipartFormData> formData) {
        NSData *data = UIImageJPEGRepresentation(_image, 0.1);
        NSString *name = @"image.jpeg";//.jpeg
        NSString *formKey = @"file";//参数Key值
        NSString *type = @"image/jpeg";
        [formData appendPartWithFileData:data name:formKey fileName:name mimeType:type];
    };
}


//- (id)jsonValidator {
//    return @{ @"imageId": [NSString class] };
//}

//- (NSString *)responseImageUrl {
//    //转成json格式
//    NSError *errorJson;
//    NSDictionary *requestDic = [NSJSONSerialization JSONObjectWithData:self.responseObject options:kNilOptions error:&errorJson];
//    return  requestDic[Response][@"showUrl"];
//}

@end
